import zipfile from '@feidao/web/atom/nodejs/zip/zip';
import html2pdf from '@feidao/web/atom/nodejs/report/html2pdf';
import { ICommonParams } from '@feidao/service/interfaces';

export default async function atom(msg: ICommonParams, action_id: string, session_id: string, spaceid: string) {

	/**
	 * 参数
	 * 访问下载地址:http://127.0.0.1:8889/export-pdf-zip?id=ceshi&spaceid=webtest
	 * 传入了两个参数
	 */
	const tpl = '<span>test</span>';

	const html = `
<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="ie=edge">
		<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes" />
		<meta name="renderer" content="webkit">
		<title></title>
		<link href="https://cdn.jsdelivr.net/npm/feidao-css/feidao.css" type="text/css" rel="stylesheet">
	</head>
	<body>
	${tpl}
	</body>
</html>
	`;
	// 调用原子操作将html内容转换为buffer
	const pdf_info = await html2pdf(html, 'landscape');

	const content = await zipfile({ file: pdf_info.buff, path: 'test.pdf' });
	return {
		attachment: '压缩包名称.zip',
		buff: content,
		content_type: 'application/octet-stream'
	};
}
